@extends('layouts.app')

@section('content')
    <section class="content-header">
        <h1>
            {!! $qrcode->title !!} 扫码日志
        </h1>
    </section>

    <?php
    $request = \Illuminate\Support\Facades\Request::all();
    ?>

    <div class="content">
        <form action="{!! route('qrcodes.show',['id'=>$qrcode->id]) !!}">
        <input type="text" name="nickname" value="{{ (isset($request['nickname'])&&$request['nickname'])?$request['nickname']:'' }}" placeholder="搜索昵称">
        {!! Form::submit('搜索', ['class' => 'btn btn-primary']) !!}
        </form>
        <div>
            <label>
                共{!! $count !!}次
            </label>
        </div>
        <div class="box box-primary">
            <div class="box-body">
                <table class="table table-responsive" id="qrcodes-table">
                    <thead>
                    <th>扫码时间</th>
                    <th>IP</th>
                    <th>HTTP_USER_AGENT</th>
                    <th>昵称</th>
                    <th>头像</th>
                    <th>性别</th>
                    <th>城市</th>
                    </thead>
                    <tbody>
                    @foreach($logs as $log)
                        <tr>
                            <td>{!! $log->created_at !!}</td>
                            <?php
                                $_info = json_decode($log->env,true);
                                    ?>
                            <td>{!! isset($_info['HTTP_X_FORWARDED_FOR'])?$_info['HTTP_X_FORWARDED_FOR']:'无' !!}</td>
                            <td>{!! $_info['HTTP_USER_AGENT'] !!}</td>
                            @if($log->user)
                            <td>{!! $log->user->nickname !!}</td>
                            <td><img src="{!! $log->user->avatar_url !!}" alt="" style="width: 40px"></td>
                            <td>{!! $log->user->sex==1?'男':'女' !!}</td>
                            <td>{!! $log->user->city !!}</td>
                            @else
                                <td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                            @endif
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        {{ $logs->appends($request)->links() }}
    </div>
@endsection
